package com.angcyo.javafx.ui

import com.angcyo.library.ex.nowTime
import javafx.event.EventHandler
import javafx.scene.input.MouseEvent

/**
 * Email:angcyo@126.com
 * @author angcyo
 * @date 2021/01/15
 */
open class DoubleEventHandler(val delay: Long = 300, val action: (MouseEvent) -> Unit) : EventHandler<MouseEvent> {
    var firstTime = 0L
    override fun handle(event: MouseEvent) {
        //双击检测
        val time = nowTime()
        if ((time - firstTime) <= delay) {
            action(event)
        } else {
            firstTime = time
        }
    }
}